package com.tihom.secutity.core.support;


import lombok.Data;

import java.io.Serializable;

/**
 * @description:
 * @author: HHJ
 * @create: 2019-09-27 13:38
 **/
@Data
public class Result<T> implements Serializable {

    /**
     * 是否请求成功
     */
    private Boolean success;

    /**
     * 返回状态码
     */
    private String code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回对象
     */
    private T data;

    private Result() {
    }

    private Result(Boolean bool, String message) {
        this.success = bool;
        this.message = message;
    }


    private Result(Boolean bool, String message, T data) {
        this.success = bool;
        this.message = message;
        this.data = data;
    }

    private Result(Boolean bool, String message, String code, T data) {
        this.success = bool;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * data非空的构建 hhj20200720
     *
     * @return
     */
    public static Result buildSuccess() {
        return new Result(Boolean.TRUE, "请求成功", "200", "");
    }

    /**
     * data非空的构建 hhj20200720
     *
     * @return
     */
    public static Result buildSuccess(Object data) {
        return new Result(Boolean.TRUE, "请求成功", "200", data);
    }

    /**
     * data非空的构建 hhj20200720
     *
     * @return
     */
    public static Result buildSuccess(String code, Object data) {
        return new Result(Boolean.TRUE, "请求成功", code, data);
    }


    public static Result buildError() {
        return new Result(Boolean.FALSE, "请求失败", "500", "");
    }


    public static Result buildError(String msg) {
        return new Result(Boolean.FALSE, msg, "500", "");
    }

    public static Result buildError(String code, String msg) {
        return new Result(Boolean.FALSE, msg, code, "");
    }

}
